package com.edu.buaa;

public class Palace {
    private String name;
    private String stars;
    private String position;
    private String heavenlyStem;
    private String earthlyBranch;
    private String description;
    private boolean isHighlighted;

    public Palace(String name, String stars, String position, String heavenlyStem, String earthlyBranch, String description) {
        this.name = name;
        this.stars = stars;
        this.position = position;
        this.heavenlyStem = heavenlyStem;
        this.earthlyBranch = earthlyBranch;
        this.description = description;
        this.isHighlighted = false;
    }

    // Getters and Setters
    public String getName() { return name; }
    public String getStars() { return stars; }
    public String getPosition() { return position; }
    public String getHeavenlyStem() { return heavenlyStem; }
    public String getEarthlyBranch() { return earthlyBranch; }
    public String getDescription() { return description; }
    public boolean isHighlighted() { return isHighlighted; }
    public void setHighlighted(boolean highlighted) { isHighlighted = highlighted; }

    // 获取地支显示文本
    public String getBranchDisplay() {
        if (heavenlyStem != null && !heavenlyStem.isEmpty() && earthlyBranch != null && !earthlyBranch.isEmpty()) {
            return heavenlyStem + "\n" + earthlyBranch;
        } else if (heavenlyStem != null && !heavenlyStem.isEmpty()) {
            return heavenlyStem;
        } else if (earthlyBranch != null && !earthlyBranch.isEmpty()) {
            return earthlyBranch;
        } else {
            return "";
        }
    }

    // 新增方法：获取适合的字体大小
    public float getOptimalTextSize(String text) {
        int lineCount = text.split("\n").length;
        int textLength = text.length();

        // 根据文本长度和行数调整字体大小
        if (lineCount > 3 || textLength > 15) {
            return 12f; // 较小字体
        } else if (lineCount > 2 || textLength > 10) {
            return 13f; // 中等字体
        } else {
            return 14f; // 正常字体
        }
    }
}